package leetcode_day._2022._202201._2131;

import java.util.*;

/**
 * @author yzh
 * @version 1.0
 * @date 2022/2/22 21:27
 * 两句话中的不常见单词
 * 算法：哈希表
 * 在句子中只出现一次，并且另一个句子中没有出现
 */
public class _30_884 {

    public String[] uncommonFromSentences(String s1, String s2) {
        String[] arr1 = s1.split(" ");
        Map<String, Integer> map1 = new HashMap<>();
        for (String s : arr1) map1.put(s, map1.getOrDefault(s, 0) + 1);
        String[] arr2 = s2.split(" ");
        Map<String, Integer> map2 = new HashMap<>();
        for (String s : arr2) map2.put(s, map2.getOrDefault(s, 0) + 1);
        List<String> ans = new ArrayList<>();
        for (String s : arr1) if (map1.get(s) == 1 && !map2.containsKey(s)) ans.add(s);
        for (String s : arr2) if (map2.get(s) == 1 && !map1.containsKey(s)) ans.add(s);
        return ans.toArray(new String[0]);
    }

}
